package br.uefs.ecomp.myBook.util;

import static org.junit.Assert.*;

import java.util.Iterator;

import org.junit.Before;
import org.junit.Test;

import br.uefs.ecomp.myBook.util.AVLTree;
import br.uefs.ecomp.myBook.util.BinaryTree;
import br.uefs.ecomp.myBook.util.DataAlreadyExistsException;
import br.uefs.ecomp.myBook.util.DataNotFoundException;

public class AVLTreeTest {

	private BinaryTree b;

	@Before
	public void setUp() throws Exception {
		b = new AVLTree();
	}

	@SuppressWarnings("rawtypes")
	@Test
	public void testIterator() throws DataAlreadyExistsException {
		b.add("teste1");
		b.add("teste2");
		b.add("teste3");

		Iterator it = b.iterator();
		assertTrue(it.hasNext());
		assertEquals((String) it.next(), "teste1");
		assertTrue(it.hasNext());
		assertEquals((String) it.next(), "teste2");
		assertTrue(it.hasNext());
		assertEquals((String) it.next(), "teste3");
		assertFalse(it.hasNext());

	}

	@Test
	public void testSearch() throws DataAlreadyExistsException,
			DataNotFoundException {
		b.add("teste1");
		b.add("teste2");
		b.add("teste3");

		assertNotNull(b.search("teste1"));
		assertNotNull(b.search("teste2"));
		assertNotNull(b.search("teste3"));

	}

	@SuppressWarnings("rawtypes")
	@Test
	public void testRemove() throws DataAlreadyExistsException,
			DataNotFoundException {
		b.add("teste1");
		b.add("teste2");
		b.add("teste3");

		b.remove("teste3");
		b.remove("teste2");
		b.remove("teste1");

		Iterator it = b.iterator();
		assertFalse(it.hasNext());

	}

}
